package com.resataurant.Service.Impl;

import com.resataurant.Dao.AdminDao;
import com.resataurant.Dto.AdminDto;
import com.resataurant.Entity.Admin;
import com.resataurant.Entity.Dish;
import com.resataurant.Entity.User;

import java.util.List;

public class AdminServiceImpl implements  com.resataurant.Service.AdminService{
    public AdminDto login(String username, String password) {
        Admin admin = new AdminDao().Login(username, password);
        AdminDto ad=new AdminDto();
        ad.setAdmin(admin);
        if (admin==null){
            ad.setSta(-1);
            return ad;
        }else {
            if(admin.getPassword().equals(password)){
                ad.setSta(1);
                return ad;
            }else {
                ad.setSta(0);
                return ad;
            }
        }
    }

    public int addDish(Dish dish) {
        return new AdminDao().addDish(dish);
    }

    @Override
    public List<Dish> searchDish(String dishName) {
        return new AdminDao().searchDish(dishName);
    }

    public List<Dish> searchDish() {
        System.out.println("sosuochenggong");
        return new AdminDao().searchDish();
    }

    public Dish searchDishById(String id) {
        return new AdminDao().searchDishById(id);
    }

    public int updateDish(Dish dish,String oldid) {
        return new AdminDao().updateDish(dish,oldid);
    }

    public int deleteDish(String id) {
        return new AdminDao().deleteDish(id);
    }

    public List<User> searchUser() {
        return new AdminDao().searchUser();
    }

    public List<User> searchUser(String username) {
        return new AdminDao().searchUserBy(username);
    }

    public User userDetail(User user) {
        return new AdminDao().userDetail(user);
    }
}
